<template>
  <el-menu router
           class="el-menu-vertical-demo">
    <el-submenu index="1">
      <template slot="title">
        <i class="el-icon-share"></i>
        <span>流程
        <el-badge :value="todoTaskCount" class="item"></el-badge></span>
      </template>
      <el-menu-item index="todo_task">待办流程
          <el-badge :value="todoTaskCount" class="item"></el-badge>
      </el-menu-item>
      <el-menu-item index="i_initiate_process">我发起的
      </el-menu-item>
      <el-menu-item index="process_list" v-if="showProcessMenu">流程列表
      </el-menu-item>
      <el-menu-item index="instance_list" v-if="showProcessMenu">进行中流程
      </el-menu-item>
      <el-menu-item index="bpmn" v-if="showProcessMenu">BPMN
      </el-menu-item>
    </el-submenu>
    <el-submenu index="2">
      <template slot="title">
        <i class="el-icon-suitcase"></i>
        <span>任务</span>
      </template>
      <el-menu-item index="task">我的任务</el-menu-item>
    </el-submenu>
    <el-submenu index="10">
      <template slot="title">
        <i class="el-icon-medal-1"></i>
        <span>KPI</span>
      </template>
      <el-menu-item index="kpi_list">党建KPI</el-menu-item>
    </el-submenu>
    <el-submenu index="9">
      <template slot="title">
        <i class="el-icon-monitor"></i>
        <span>会议</span>
      </template>
      <el-menu-item @click="handleMenuClick('党务工作会')">党务工作会
      </el-menu-item>
      <el-menu-item @click="handleMenuClick('党政联席会')">党政联席会
      </el-menu-item>
      <el-menu-item @click="handleMenuClick('业务会')">业务工作会
      </el-menu-item>
      <el-menu-item @click="handleMenuClick('评审会')">评审会
      </el-menu-item>
    </el-submenu>
    <el-submenu index="8">
      <template slot="title">
        <i class="el-icon-shopping-cart-full"></i>
        <el-link href="order_list">搅拌头业务</el-link>
      </template>
      <el-menu-item index="create_tool_order">订单审批
      </el-menu-item>
      <el-menu-item index="production_management">生产管理
          <el-badge :value="toolTodoCount" class="item"></el-badge>
      </el-menu-item>
      <el-menu-item index="tool_purchase">发货交付
      </el-menu-item>
      <el-menu-item index="tool_purchase">售后服务
      </el-menu-item>
      <el-menu-item index="tool_purchase">库存管理
      </el-menu-item>
      <el-menu-item index="tool_drawing_data">技术资料
      </el-menu-item>
    </el-submenu>
    <el-submenu index="3">
      <template slot="title">
        <i class="el-icon-s-custom"></i>
        <span>CRM</span>
      </template>
      <el-menu-item index="/guest_info">客户信息
      </el-menu-item>
    </el-submenu>
    <el-submenu index="4">
      <template slot="title">
        <i class="el-icon-collection"></i>
        <span>项目</span>
      </template>
      <el-menu-item index="/">立项</el-menu-item>
    </el-submenu>
    <el-submenu index="5">
      <template slot="title">
        <i class="el-icon-s-check"></i>
        <span>评审</span>
      </template>
      <el-menu-item index="/review">评审列表</el-menu-item>
    </el-submenu>
    <el-submenu index="6">
      <template slot="title">
        <i class="el-icon-house"></i>
        <span>物资管理</span>
      </template>
      <el-menu-item index="/wms">外购件</el-menu-item>
      <el-menu-item index="/wip">在制品</el-menu-item>
    </el-submenu>
    <el-submenu index="7">
      <template slot="title">
        <i class="el-icon-setting"></i>
        <span>系统</span>
      </template>
      <el-menu-item index="/user_list">
        用户列表
      </el-menu-item>
      <el-menu-item index="/user_update">
        修改个人信息
      </el-menu-item>
      <el-menu-item index="/process_form">
        流程表单设置
      </el-menu-item>
      <el-menu-item index="/business_data">
        业务数据配置
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
import {mapState} from 'vuex';

export default {
  name: "Aside",
  data() {
    return {
      showProcessMenu: false
    }
  },
  computed: {
    ...mapState({
      todoTaskCount: state => state.todoTaskCount,
      toolTodoCount: state => state.todoTaskCountModule['搅拌头流程']
    })
  },
  methods: {
    checkPermissions() {
      const userInfo = JSON.parse(localStorage.getItem('user'))
      this.showProcessMenu = userInfo.authorities.some(authority => authority.authority === 'ROLE_SHOW_PROCESSMENU')
    },
    handleMenuClick(meetingType) {
      this.$router.push(
          {
            name: 'Meeting',
            query: {
              meetingType: meetingType
            }
          }
      )
    }
  },
  mounted() {
    this.checkPermissions()
  }
}
</script>

<style scoped>
::v-deep.el-menu {
  border: none;
}

::v-deep.el-submenu {
  border-bottom: 1px solid #eaeaea;
}
</style>